<?php
/**
 * Register a new user 			Registed as 'action/user/register'
 *
 * $name
 * $username 
 * $email
 * $pass1
 * $pass2
 */

#################################################################
#								ACTION
#################################################################
if($_CONTEXT==CONTEXT_ACTION){
	
	$name= trim(blg_get_input('name'));
	$username= trim(blg_get_input('username'));
	$email= blg_get_input('email');
	$pass1= blg_get_input('pass1');
	$pass2= blg_get_input('pass2');
	
	$user= BlgUser::create($name, $username, $email, $pass1, $pass2);
	
	//If register failed
	if($user===FALSE){
		//Save form data
		blg_session_set('form_register_failed', array('name' => $name,'username' => $username,'email' => $email,'pass1' => $pass1,'pass2' => $pass2), TRUE);	
		forward();
	}
	
	//If successfull, send email
	blg_user_send_registrarion_email($user->guid);	
	
	//Add messages
	blg_msg_add(blg_echo('register:success', array($name)));
	blg_msg_add(blg_echo('register:confirm1', array($email)), true);
	blg_msg_add(blg_echo('register:confirm2', array($email)), true);
	blg_msg_add(blg_echo('email:in:spam'));
	forward();

}
#################################################################
#								ACCESS
#################################################################
elseif($_CONTEXT==CONTEXT_ACCESS){	 
	$_ACCESS= (blg_user_is_logged_in()===FALSE && blg_security_grant_from_input(3600));
}
